<form name="editForm" role="form" novalidate (ngSubmit)="save()" #editForm="ngForm">

    <div class="modal-header">
        <h4 class="modal-title" id="myMessageLabel">Create or edit a Message</h4>
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"
                (click)="clear()">&times;</button>
    </div>
    <div class="modal-body">
        <jhi-alert-error></jhi-alert-error>
        <div class="form-group" [hidden]="!message.id">
            <label for="id">ID</label>
            <input type="text" class="form-control" id="id" name="id"
                   [(ngModel)]="message.id" readonly />
        </div>
        <div class="form-group">
            <label class="form-control-label" for="field_messageId">Message Id</label>
            <input type="text" class="form-control" name="messageId" id="field_messageId"
                [(ngModel)]="message.messageId" required />
            <div [hidden]="!(editForm.controls.messageId?.dirty && editForm.controls.messageId?.invalid)">
                <small class="form-text text-danger"
                   [hidden]="!editForm.controls.messageId?.errors?.required">
                   This field is required.
                </small>
            </div>
        </div>
        <div class="form-group">
            <label class="form-control-label" for="field_userId">User Id</label>
            <input type="number" class="form-control" name="userId" id="field_userId"
                [(ngModel)]="message.userId" required />
            <div [hidden]="!(editForm.controls.userId?.dirty && editForm.controls.userId?.invalid)">
                <small class="form-text text-danger"
                   [hidden]="!editForm.controls.userId?.errors?.required">
                   This field is required.
                </small>
                <small class="form-text text-danger"
                    [hidden]="!editForm.controls.userId?.errors?.number">
                    This field should be a number.
                </small>
            </div>
        </div>
        <div class="form-group">
            <label class="form-control-label" for="field_avatar">Avatar</label>
            <input type="text" class="form-control" name="avatar" id="field_avatar"
                [(ngModel)]="message.avatar"  />
        </div>
        <div class="form-group">
            <label class="form-control-label" for="field_userName">User Name</label>
            <input type="text" class="form-control" name="userName" id="field_userName"
                [(ngModel)]="message.userName" required />
            <div [hidden]="!(editForm.controls.userName?.dirty && editForm.controls.userName?.invalid)">
                <small class="form-text text-danger"
                   [hidden]="!editForm.controls.userName?.errors?.required">
                   This field is required.
                </small>
            </div>
        </div>
        <div class="form-group">
            <label class="form-control-label" for="field_toUserId">To User Id</label>
            <input type="number" class="form-control" name="toUserId" id="field_toUserId"
                [(ngModel)]="message.toUserId" required />
            <div [hidden]="!(editForm.controls.toUserId?.dirty && editForm.controls.toUserId?.invalid)">
                <small class="form-text text-danger"
                   [hidden]="!editForm.controls.toUserId?.errors?.required">
                   This field is required.
                </small>
                <small class="form-text text-danger"
                    [hidden]="!editForm.controls.toUserId?.errors?.number">
                    This field should be a number.
                </small>
            </div>
        </div>
        <div class="form-group">
            <label class="form-control-label" for="field_message">Message</label>
            <input type="text" class="form-control" name="message" id="field_message"
                [(ngModel)]="message.message"  />
        </div>
        <div class="form-group">
            <label class="form-control-label" for="field_time">Time</label>
            <div class="d-flex">
                <input id="field_time" type="datetime-local" class="form-control" name="time" [(ngModel)]="message.time"
                  />
            </div>
        </div>
        <div class="form-group">
            <label class="form-control-label" for="field_messageType">Message Type</label>
            <input type="number" class="form-control" name="messageType" id="field_messageType"
                [(ngModel)]="message.messageType" required />
            <div [hidden]="!(editForm.controls.messageType?.dirty && editForm.controls.messageType?.invalid)">
                <small class="form-text text-danger"
                   [hidden]="!editForm.controls.messageType?.errors?.required">
                   This field is required.
                </small>
                <small class="form-text text-danger"
                    [hidden]="!editForm.controls.messageType?.errors?.number">
                    This field should be a number.
                </small>
            </div>
        </div>
        <div class="form-group">
            <label class="form-control-label" for="field_status">Status</label>
            <input type="text" class="form-control" name="status" id="field_status"
                [(ngModel)]="message.status" required />
            <div [hidden]="!(editForm.controls.status?.dirty && editForm.controls.status?.invalid)">
                <small class="form-text text-danger"
                   [hidden]="!editForm.controls.status?.errors?.required">
                   This field is required.
                </small>
            </div>
        </div>

    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal" (click)="clear()">
            <span class="fa fa-ban"></span>&nbsp;<span>Cancel</span>
        </button>
        <button type="submit" [disabled]="editForm.form.invalid || isSaving" class="btn btn-primary">
            <span class="fa fa-save"></span>&nbsp;<span>Save</span>
        </button>
    </div>
</form>
